home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / FMAT Editor 1.0.1 folder / FormatVal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-19  |  1.1 KB  |  52 lines  |  [TEXT/KAHL]

  1. #include <Packages.h>
  2.  
  3. #include "FormatVal.h"
  4.  
  5. /*
  6.     -- Michael Hecht (Michael_Hecht@mac.sas.com)
  7.        August 5, 1993
  8. */
  9.  
  10.  
  11. OSErr FormatVal( double x, short formatID, StringPtr formattedX )
  12. {
  13.     NumberParts            parts;
  14.  
  15.     NumFormatString        **format;
  16.     Handle                itl4;
  17.     long                offset, length;
  18.  
  19.     FormatStatus        status;
  20.  
  21.  
  22.     /* Just in case! */
  23.     Length( formattedX ) = 0;
  24.  
  25.     /* Get default Number Parts resource/offset/length */
  26.     GetIntlResourceTable( iuCurrentScript, iuNumberPartsTable, &itl4, &offset, &length );
  27.     if( !itl4 )
  28.         return paramErr;
  29.  
  30.     /* Retrieve default Number Parts Table */
  31.     parts = *( NumberPartsPtr )( *itl4 + offset );
  32.  
  33.     /* Retrieve canonical format */
  34.     format = ( NumFormatString ** )GetResource( 'FMAT', formatID );
  35.     if( !format )
  36.         return resNotFound;
  37.  
  38.     /* Lock it */
  39.     HLock(( Handle )format );
  40.  
  41.     /* Format it! */
  42. //    This should work in THINK C 6.0, but it doesn't due to an H file error. Therefore,
  43. //    we coerce x into an extended80.
  44. //    status = ExtendedToString( x, *format, &parts, formattedX );
  45.     status = ExtendedToString( *( extended80 * )&x, *format, &parts, formattedX );
  46.  
  47.     /* Unlock the canonical format */
  48.     HUnlock(( Handle )format );
  49.  
  50.     return status;
  51. }
  52.